using UnityEngine;
using System.Collections;

public class splashScreen : MonoBehaviour {

	public Texture splash;
	public Color color;
	public float alpher;
	public float speedIncrease;
	public bool incre;
	public float count;
	public string nextScene;
	
	// Use this for initialization
	void Start () {
		incre = true;		
		alpher = 0;
	}
	void OnGUI()
	{
		GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpher));
		GUI.DrawTexture(new Rect((Screen.width/2)-(splash.width/2), (Screen.height*.5f)-(splash.height /2), splash.width,splash.height), splash, ScaleMode.ScaleToFit, true, 0);
	}
	// Update is called once per frame
	void Update () {
		GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpher));
		if(alpher >=1)
		{
			alpher = 1;
			count += 1*Time.deltaTime;
			if(count>=3)
			{
				incre = false;
				count = 0;
			}
		}
		if(incre)
		{
			alpher += speedIncrease * Time.deltaTime;
		}
		else
		{
			alpher -= speedIncrease * Time.deltaTime;
			if(alpher <=-.025)
			{
				Application.LoadLevel(nextScene);
			}
		}
		GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpher));
	}
}
